package ru.ncedu.java.sean.robots.Test.java;
import java.util.Random;

public class World 
{
	Robot[] Robots;
	int width;
	int height;
	int countRobots;
	
	public World(int w,int h,int count)
	{
		int a,b;
		this.width=w;
		this.height=h;
		this.countRobots=count;
		this.Robots = new Robot[count];
		Random r = new Random();
		for(int i=0;i<Robots.length;++i)
		{
			Robots[i]=new Robot();
			Robots[i].id=i;
			a=r.nextInt(w);
			b=r.nextInt(h);
			Robots[i].location.addData(a,b);
			Robots[i].status=1;
		}
	}
	
	void collisionRobots()
	{
		int j;
		for(int i=0;i<this.Robots.length;++i)
		{
			for(j=i+1;j<this.Robots.length;++j)
			{
			
				if(Robots[i].location.x==Robots[j].location.x)
					if(Robots[i].location.y==Robots[j].location.y)
					{
						Robots[i].status=0;
						break;
					}
			}
		}
	}
	
	public void printWorld()
	{
		System.out.println("WORLD:");
		System.out.println("width="+this.width+" height="+this.height+"count robots="+this.countRobots);
		System.out.println("ROBOTS:");
		for(int i=0;i<this.Robots.length;++i)
			this.Robots[i].printRobot();
	}
	
	void moveRobots()
	{
		for(int i=0;i<Robots.length;++i)
		{
			Robots[i].moveUp();
			//Robots[i].moveDown();
			//Robots[i].moveLeft();
			//Robots[i].moveRight();
		}
	}
	
	public static void main(String[] args)
	{
		int a=5,b=5,n=5;
		World w = new World(a,b,n);
		w.printWorld();
		w.collisionRobots();
		w.printWorld();
		w.moveRobots();
		w.collisionRobots();
		w.printWorld();
	}
}
